package com.ibiaoke.goods.dao;

import com.ibiaoke.common.base.BaseDao;
import com.ibiaoke.common.base.Page;
import com.ibiaoke.common.utils.StringUtils;
import com.ibiaoke.goods.entity.GoodStockExample;
import com.ibiaoke.goods.entity.ReserveGoods;
import com.ibiaoke.goods.entity.ReserveGoodsExample;
import com.ibiaoke.goods.mapper.ReserveGoodsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

@Repository
public class ReserveGoodsDao  extends BaseDao<ReserveGoods, ReserveGoodsExample, Integer, ReserveGoodsMapper> {
    @Autowired
    private ReserveGoodsMapper reserveGoodsMapper;
    @Override
    public ReserveGoodsMapper getMapper() {
        return reserveGoodsMapper;
    }


    public List<ReserveGoods> findGoodStockList(String goodName, Integer goodId, Date reserveStartTime,
                                                Date reserveEndTime, Integer shopId, Page page) {

        ReserveGoodsExample example = new ReserveGoodsExample();
        ReserveGoodsExample.Criteria criteria = example.createCriteria();

        if (StringUtils.isNotEmpty(goodName)) {
            criteria.andGoodNameLike("%" + goodName + "%");
        }

        if(goodId != null){
            criteria.andGoodIdEqualTo(goodId);
        }

        if (reserveStartTime != null) {
            criteria.andReserveTimeLessThanOrEqualTo(reserveStartTime);
        }

        if(reserveEndTime != null){
            criteria.andReserveTimeLessThanOrEqualTo(reserveEndTime);
        }

        if(shopId != null){
            criteria.andShopIdEqualTo(shopId);
        }

        page.setTotalCount(reserveGoodsMapper.countByExample(example));
        example.setLimitStart(page.limitStart());
        example.setLimitEnd(page.limitEnd());
        example.setOrderByClause("create_time desc");
        return selectByExample(example);
    }




}
